package cn.mxz.robots.web.service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cn.mxz.rds.pojo.GaoKaoProvince;
import cn.mxz.rds.service.GaoKaoProvinceService;
import cn.mxz.robots.util.RobotsUtlis;

/**
 * Rds 本地化service
 * 
 * @author cuizhennan<cuizhennan@mouge.wang>
 * @since 2015-06-29
 */
@Component
@Scope("prototype")
public class RdsService
{
	private final static Map<String, String> memCacheMap = new ConcurrentHashMap<String, String>();

	public String getProvconf(String year, String province)
	{
		if (!RobotsUtlis.isElemetns(province, "[\u4e00-\u9fa5]") || !RobotsUtlis.isElemetns(year, "\\d{4}"))
		{
			return "params type Exception." + year + "==>" + province;
		}

		String infoConf = memCacheMap.get(year + "-" + province);

		if ("".equals(infoConf) || infoConf == null)
		{
			GaoKaoProvinceService gaoKaoProvinceService = new GaoKaoProvinceService();
			GaoKaoProvince gaoKaoProvince = gaoKaoProvinceService.findByYearAndProvince(year, province);

			if (gaoKaoProvince == null)
			{
				return "not extsis province " + year + "-" + province;
			}

			infoConf = gaoKaoProvince.getInfoConfig();

			memCacheMap.put(year + "-" + province, infoConf);
		}

		return infoConf;
	}
}
